import numpy as np
import matplotlib.pyplot as plt
from time import clock
from search.all import *
from problem_agent import *
import problems
import heuristics
from sys import maxint 
reload(heuristics)
reload(problems)

class astar_solution(ProblemAgent):
    
    def __init__(self, h):
        self.h = h
        
    def solve(self, problem_state, time_limit = NO_LIMIT):
        '''
        This is the method called by the runner of this agent.
        It includes the code that solves the problem.
        
        @param problem_state: Initial problem state.
        @param time_limit: The time limit for this agent.
        @return: A list of ProblemActions that solves the given problem.
        '''
        star = AStar()
        start = clock()
            
        s = star.find(problem_state,self.h)
        end = clock()
        if s: return (end-start, len(s))
        else:         return (end-start, None)

